home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_197 / stevie / raw.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  85 lines

  1. /*
  2.  * raw.c 
  3.  *
  4.  * This is a routine for setting a given stream to raw or cooked mode on the
  5.  * Amiga . This is useful when you are using Lattice C to produce programs
  6.  * that want to read single characters with the "getch()" or "fgetc" call. 
  7.  *
  8.  * Written : 18-Jun-87 By Chuck McManis.
  9.  */
  10.  
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <stdio.h>
  14. #include <ios1.h>
  15. #include <error.h>
  16.  
  17. extern int      errno;        /* The error variable */
  18.  
  19. /*
  20.  * Function raw() - Convert the specified file pointer to 'raw' mode. This
  21.  * only works on TTY's and essentially keeps DOS from translating keys for
  22.  * you, also (BIG WIN) it means getch() will return immediately rather than
  23.  * wait for a return. You lose editing features though. 
  24.  */
  25. long
  26. raw(fp)
  27.     FILE           *fp;
  28.  
  29. {
  30.     struct MsgPort *mp;        /* The File Handle message port */
  31.     struct FileHandle *afh;
  32.     struct UFB     *ufb;
  33.     long            Arg[1], res;
  34.  
  35.     ufb = (struct UFB *) chkufb(fileno(fp));    /* Step one, get the file
  36.                          * handle */
  37.     afh = (struct FileHandle *) (ufb->ufbfh);
  38.  
  39.     if (!IsInteractive(afh)) {    /* Step two, check to see if it's a console */
  40.     errno = ENOTTY;
  41.     return (-1);
  42.     }
  43.     /* Step three, get it's message port. */
  44.     mp = ((struct FileHandle *) (BADDR(afh)))->fh_Type;
  45.     Arg[0] = -1L;
  46.     res = SendPacket(mp, ACTION_SCREEN_MODE, Arg, 1);    /* Put it in RAW: mode */
  47.     if (res == 0) {
  48.     errno = ENXIO;
  49.     return (-1);
  50.     }
  51.     return (0);
  52. }
  53.  
  54. /*
  55.  * Function - cooked() this function returns the designate file pointer to
  56.  * it's normal, wait for a <CR> mode. This is exactly like raw() except that
  57.  * it sends a 0 to the console to make it back into a CON: from a RAW: 
  58.  */
  59.  
  60. long
  61. cooked(fp)
  62.     FILE           *fp;
  63.  
  64. {
  65.     struct MsgPort *mp;        /* The File Handle message port */
  66.     struct FileHandle *afh;
  67.     struct UFB     *ufb;
  68.     long            Arg[1], res;
  69.  
  70.     ufb = (struct UFB *) chkufb(fileno(fp));
  71.     afh = (struct FileHandle *) (ufb->ufbfh);
  72.     if (!IsInteractive(afh)) {
  73.     errno = ENOTTY;
  74.     return (-1);
  75.     }
  76.     mp = ((struct FileHandle *) (BADDR(afh)))->fh_Type;
  77.     Arg[0] = 0;
  78.     res = SendPacket(mp, ACTION_SCREEN_MODE, Arg, 1);
  79.     if (res == 0) {
  80.     errno = ENXIO;
  81.     return (-1);
  82.     }
  83.     return (0);
  84. }
  85.